import request from "@/utils/request";

const USER_BASE_URL = "/core/logistics";

const planDeliverGoodsApi = {
  /** 查询配送单维护列表
   * @param params 查询参数
   * @returns 配送单维护列表
   * @example
   */
  getDeliveryOrderMaintenanceList: (params: planDeliverGoodsQuery) => {
    let query = encodeURIComponent(JSON.stringify(params));
    return request<any, planDeliverGoodsMaintenance[]>({
      url: `${USER_BASE_URL}/delivery/query?object=${query}`,
      method: "get",
    });
  },
  /** 修改配送单
   * @param params 配送单维护对象
   * @returns 配送单维护对象
   * @example
   */
  updateDeliveryOrder: (params: planDeliverGoodsMaintenance) => {
    return request<any, planDeliverGoodsMaintenance>({
      url: `${USER_BASE_URL}/delivery/update`,
      method: "post",
      data: params,
    });
  },

  /**
   * 配送完成
   * @param params 配送单维护对象
   * @returns 配送单维护对象
   * @example
   */
  completeDelivery: (params: planDeliverGoodsMaintenance) => {
    return request<any, planDeliverGoodsMaintenance>({
      url: `${USER_BASE_URL}/delivery/delivery`,
      method: "post",
      data: params,
    });
  },
};
export default planDeliverGoodsApi;

export interface planDeliverGoodsMaintenance {
  id?: number; //ID
  deliveryOrderId?: string; //运单号
  customerCode?: string; //客户编号
  customerName?: string; //客户名称
  contactPerson?: string; //联系人
  contactPhone?: string; //联系电话
  deliveryAddress?: string; //地址
  deliveryCoordinates?: string; //经纬度
  licensePlate?: string; //车牌号
  driverName?: string; //司机
  driverPhone?: string; //司机电话
  loadingPosition?: string; //装货位置
  basketRecoveryStatus?: number; //篮框回收
  completionTime?: string; //装货时间
  status?: number; //状态
  detail?: {
    product?: {
      id?: string;
      name?: string;
    }[];
    baskets?: {
      id?: string;
      quantity?: number;
    }[];
    grossWeight?: number; //毛重
    netWeight?: number; //净重
  }; //详情
  attachment?: string;
  remark?: string; //备注
}

export interface planDeliverGoodsQuery extends PageQuery {
  /**
   * 车牌号
   */
  plateNumber?: string;
  /**
   * 客户名称
   */
  companyName?: string;
  /**
   * 联系人
   */
  contactPerson?: string;
  /**
   * 状态
   */
  status?: number;
}
